<template>
  <div class="index">
    <van-nav-bar title left-arrow @click-left="onClickLeft" fixed />
    <div class="main" :style="{background:'url('+initData.poster+')  0% 0% / 100% 2.2rem no-repeat'}">
      <div class="mainTitle">
        <div class="title">{{initData.title}}</div>
        <div class="sub">
          <div class="left">
            <div>
              <img src="../assets/images/chakan.png" alt />
              <span>{{initData.view}}</span>
            </div>
            <div>
              <img src="../assets/images/web-icon-.png" alt />
              <span>{{initData.follow_number}}</span>
            </div>
            <div>
              <img src="../assets/images/shoucang.png" alt />
              <span>{{initData.collect}}</span>
            </div>
          </div>
          <div class="right">
            <img src="../assets/images/obj.png" alt />
            <span>交易保障</span>
          </div>
        </div>
      </div>
      <div class="ps">*该活动不支持退款</div>
      <div class="info">
        <div class="time">
          <img src="../assets/images/shijian.png" alt />
          <span>{{initData.start_time*1000|changeNum|formatDate("yyyy-MM-dd hh:mm")}}至{{initData.end_time*1000|changeNum|formatDate("yyyy-MM-dd hh:mm")}}</span>
        </div>
        <div class="address">
          <div class="left">
            <img src="../assets/images/ditu.png" alt />
            <span>{{initData.area_info}}</span>
          </div>
          <div class="right">
            <van-icon name="arrow" />
          </div>
        </div>
        <div class="num">
          <img src="../assets/images/wo.png" alt />
          <span>已报名{{initData.in_number}}人／不限制名额</span>
        </div>
        <div class="price">
          <img src="../assets/images/dashang.png" alt />
          <span v-if="initData.ticket_min!='0.00'">¥ {{initData.ticket_min}}-{{initData.ticket_max}}</span>
          <span v-else>¥ 免费</span>
        </div>
      </div>
    </div>
    <div class="mainUnit">
      <div class="mainInfo">
        <div class="pic">
          <img :src="initData.avatar" alt />
        </div>
        <div class="text">
          <div class="name">{{initData.username}}</div>
          <div class="num">
            <div class="num1">{{initData.activity_number}}活动</div>
            <div class="num2">{{initData.follow_number}}粉丝</div>
          </div>
        </div>
      </div>
      <div class="introduction">{{initData.bio}}</div>
      <div class="action">
        <div class="left" @click="focusOn">
          <img src="../assets/images/focus.png" alt />
        </div>
        <div class="right" @click="toStation">
          <img src="../assets/images/btn.png" alt />
        </div>
      </div>
    </div>
    <div class="activityDetail">
      <div>
        <img src="../assets/images/detail.png" alt />
      </div>
      <div v-html="initData.content" class="activityContent"></div>
      <div>
        <img src="../assets/images/actibity.png" alt />
      </div>
    </div>
    <div class="footer">
      <div class="left">
        <div class="actionItem" @click="showDialog">
          <img src="../assets/images/consult.png" alt />
          <span>咨询</span>
        </div>
        <div class="actionItem" @click="showDialog">
          <img src="../assets/images/qun.png" alt />
          <span>群聊</span>
        </div>
        <div class="actionItem" @click="showDialog">
          <img src="../assets/images/callect.png" alt v-if="initData.is_collection==0" />
          <img src="../assets/images/callect2.png" alt v-else />
          <span>收藏</span>
        </div>
      </div>
      <div class="right" @click="signUp">我要报名</div>
    </div>

    <div class="downloadApp">
      <van-dialog
        v-model="showDownload"
        :show-confirm-button="false"
        :close-on-click-overlay="true"
      >
        <div class="downloadDialog">
          <div class="text">请前往现信APP继续操作</div>
          <div class="btn" @click="downloadApp">马上下载现信APP</div>
        </div>
      </van-dialog>
    </div>
    <div class="chooseSku">
      <van-actionsheet v-model="showSku" :title="initData.title">
        <div class="content">
          <div class="ticket">
            <div
              class="row row1"
              v-for="(item,index) in initData.ticket_info"
              :key="index"
              @click="chooseTicket(item)"
            >
              <div class="ticketBox" :class="{selectTicket:item.is_select}">
                <div class="name">{{item.ticket_name}}</div>
                <div class="price" v-if="initData.fee_type==0&&initData.can_buy!=0">免费</div>
                <div
                  class="price"
                  v-if="initData.fee_type!=0&&initData.can_buy!=0"
                >¥ {{item.ticket_price}}</div>
                <div class="price price2" v-if="initData.can_buy==0">已购买</div>
              </div>
            </div>
            <!-- <div class="row row2">
              <div class="ticketBox selectTicket" >
                <div class="name">成人票</div>
                <div class="price">¥ 854</div>
              </div>
              <div class="ticketBox">
                <div class="name">成人票</div>
                <div class="price">¥ 854</div>
              </div>
            </div>-->
          </div>
          <div class="num" v-if="initData.fee_type!=0">
            <label>数量：</label>
            <van-stepper v-model="numValue" integer :min="1" :max="numMax" @change="onChange" />
          </div>
          <div class="next">
            <div class="total" v-if="initData.fee_type==0">合计： ¥ 0</div>
            <div class="total" v-else>合计： ¥ {{totalPrice}}</div>
            <div class="btn" @click="toSignUpInfo">下一步</div>
          </div>
        </div>
      </van-actionsheet>
    </div>
    <div class="chooseSku signUp">
      <van-actionsheet v-model="showSignUp" title="   ">
        <div class="content">
          <div class="form">
            <div class="name">
              <label>姓名：</label>
              <input type="text" v-model="name" />
            </div>
            <div class="phone">
              <label>手机：</label>
              <input type="number" v-model="phone" />
            </div>
          </div>
          <div class="next" v-if="initData.can_buy!=0">
            <div class="total" v-if="initData.fee_type==0">合计： ¥ 0</div>
            <div class="total" v-else>合计： ¥ {{totalPrice}}</div>
            <div class="btn" @click="signUpMethod">下一步</div>
          </div>
          <div class="next" v-if="initData.can_buy==0">
            <div class="total" v-if="initData.fee_type==0">合计： ¥ 0</div>
            <div class="total" v-else>合计： ¥ {{totalPrice}}</div>
            <div class="btn btn2">下一步</div>
          </div>
        </div>
      </van-actionsheet>
    </div>
    <div v-if="showBind">
      <bindPhone :uid="uid" :activity_id="activity_id"></bindPhone>
    </div>
  </div>
</template>
<script>
import vuefilter from "../common/vuefilter.js";
export default {
  name: "index",
  filters: {
    formatDate: vuefilter.formatDate,
    changeNum: vuefilter.changeNum
  },
  data() {
    return {
      showBind: false,
      showSku: false,
      //选择票的数量
      numValue: 1,
      initData: {},
      phone: "",
      code: "",
      codeText: "获取验证码",
      codeTime: 0,
      //显示下载APP弹窗
      showDownload: false,
      totalPrice: 0,
      numMax: 9999999,
      //显示报名弹窗
      showSignUp: false,
      //活动ID
      activity_id: "",
      //选择的票种ID
      special_id: "",
      name: "",
      phone: "",
      // 免费票订单号
      orderId: "",
      uid: "",
      activity_id: ""
    };
  },
  created() {},
  mounted() {
    if (this.$route.query.uid) {
      this.uid = this.$route.query.uid;
    }
    if (this.$route.query.activity_id) {
      this.activity_id = this.$route.query.activity_id;
    } else {
      // this.activity_id = 142;
      this.activity_id = 181;
    }
    // if (!this.$cookies.get("token")) {
    //   this.$router.push({
    //     path: "/login",
    //     query: {
    //       uid: this.uid,
    //       activity_id: this.activity_id
    //     }
    //   });
    //   return;
    // }

    this.getInitData();
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    showDialog() {
      if (this.$cookies.get("first_login")==0) {
        this.showDownload = true;
      } else {
        this.showBind = true;
      }
    },
    //报名
    signUp() {

      if (this.$cookies.get("first_login")==0) {
        this.showSku = true;
      } else {
        this.showBind = true;
      }
    },
    //下一步
    toSignUpInfo() {
      let onoff = false;
      this.initData.ticket_info.forEach((item, index) => {
        if (item.is_select) {
          onoff = true;
        }
      });
      if (!onoff) {
        this.$message({
          message: "您还没有选择票种",
          type: "error"
        });
        return false;
      }
      if (this.initData.fee_type == 0) {
        this.showSku = false;
        this.showSignUp = true;
      } else {
        this.$router.push({
          path: "/signUpInfo",
          query: {
            num: this.numValue,
            totalPrice: this.totalPrice,
            activity_id: this.activity_id,
            special_id: this.special_id,
            uid: this.uid
          }
        });
      }
    },
    //去主办方的小站
    toStation() {
      if (this.$cookies.get("first_login")==0) {
        this.$router.push({
          path: "/station",
          query: {
            owner_id: this.initData.owner_id,
            uid: this.uid,
            activity_id: this.activity_id
          }
        });
      } else {
        this.showBind = true;
      }
    },

    //获取初始化数据
    async getInitData() {
      let params = {
        token: this.$cookies.get("token"),
        activity_id: this.activity_id
      };
      const res = await this.$axios.post(this.$api.getActivityDetail, params);
      if (res.code == 1) {
        this.initData = res.data;
        this.initData.ticket_info.forEach((item, index) => {
          item.is_select = false;
        });
      } else {
        this.$message({
          message: "获取用户协议失败：" + res.msg,
          type: "error"
        });
      }
    },
    //选择票种
    chooseTicket(item) {
      if (this.initData.can_buy != 0) {
        this.special_id = item.id;
        let is_true = item.is_select;
        this.initData.ticket_info.forEach((item, index) => {
          item.is_select = false;
        });
        if (is_true) {
          item.is_select = false;
          if (this.initData.fee_type != 0) {
            this.totalPrice = 0;
            this.totalPrice = this.totalPrice.toFixed(2);
          }
        } else {
          item.is_select = true;
          if (this.initData.fee_type != 0) {
            this.numMax = item.ticket_rest;
            this.totalPrice = Number(item.ticket_price) * this.numValue;
            this.totalPrice = this.totalPrice.toFixed(2);
          }
        }
      }
      this.$forceUpdate();
    },
    //改变数量
    onChange(value) {
      this.initData.ticket_info.forEach((item, index) => {
        if (item.is_select) {
          this.totalPrice = Number(item.ticket_price) * value;
          this.totalPrice = this.totalPrice.toFixed(2);
        }
      });
    },
    //报名接口
    async signUpMethod() {
      let info = [
        [
          {
            value: this.name,
            key: "username",
            name: "姓名",
            is_required: 1
          },
          {
            value: this.phone,
            key: "phone",
            name: "手机",
            is_required: 1
          }
        ]
      ];

      let params = {
        token: this.$cookies.get("token"),
        activity_id: this.activity_id,
        special_id: this.special_id,
        ticket_info: JSON.stringify(info)
        // ticket_info: info
      };
      const res = await this.$axios.post(this.$api.getActivityIn, params);
      if (res.code == 1) {
        this.orderId = res.data.out_trade_no;
        this.$router.push({
          path: "/activity",
          query: {
            orderId: this.orderId,
            uid: this.uid,
            activity_id: this.activity_id
          }
        });
      } else {
        this.$message({
          message: "报名失败：" + res.msg,
          type: "error"
        });
      }
    },
    //关注
    async focusOn() {
      if (this.$cookies.get("first_login")!=0) {
        this.showBind = true;
        return;
      }
      let params = {
        token: this.$cookies.get("token"),
        id: this.initData.owner_id
      };
      const res = await this.$axios.post(this.$api.follow, params);
      if (res.code == 1) {
        this.$message({
          message: res.msg,
          type: "success"
        });
      } else {
        this.$message({
          message: "操作失败：" + res.msg,
          type: "error"
        });
      }
    },
    //下载APP
    downloadApp() {
      var u = navigator.userAgent;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      if (isiOS) {
        window.location.href = this.$api.downloadUrl;
      }
      if (isAndroid) {
        window.location.href = this.$api.downloadUrl;
      }
    }
  }
};
</script>
<style scoped>
.index {
  padding-bottom: 0.5rem;
}
.van-nav-bar {
  background: none;
}
.main {
  /* background: url("../assets/images/VCG41164191362.png") no-repeat; */
  background-size:100% 2.2rem;
  /* background-size:100% 100%; */
  width: 100%;
  background-color: #fff;
  /* background-size: 100% auto; */
  padding-top: 1.2rem;
}
.van-nav-bar .van-icon {
  color: #fff;
}
[class*="van-hairline"]::after {
  border: none;
}
.mainTitle {
  width: 80%;
  margin: 0 auto;
  background: #fff;
  box-shadow: 1px 0px 9px 0px rgba(71, 71, 71, 0.15);
  border-radius: 5px;
  padding: 0.22rem 0.2rem 0.16rem;
}
.mainTitle .title {
  font-size: 0.16rem;
  font-family: PingFangSC-Medium;
  font-weight: 500;
  color: rgba(2, 2, 2, 1);
  margin-bottom: 0.2rem;
}
.mainTitle .sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.mainTitle .sub .left {
  display: flex;
  align-items: center;
}
.mainTitle .sub .left > div {
  display: flex;
  align-items: center;
  margin-right: 0.12rem;
}
.mainTitle .sub .left > div img {
  width: 0.13rem;
}
.mainTitle .sub .left > div span {
  font-size: 0.12rem;
  color: #8b8b8b;
  padding-left: 0.06rem;
}
.mainTitle .sub .right {
  display: flex;
  align-items: center;
}
.mainTitle .sub .right img {
  width: 0.17rem;
}
.mainTitle .sub .right span {
  font-size: 0.12rem;
  color: #8b8b8b;
  padding-left: 0.05rem;
}
.ps {
  margin-top: 0.15rem;
  text-align: center;
  width: 100%;
  font-size: 0.12rem;
  color: #a0a0a0;
}
.info {
  margin-top: 0.25rem;
  padding: 0 0.15rem 0.2rem 0.33rem;
}
.info > div {
  display: flex;
  align-items: center;
  margin-bottom: 0.2rem;
}
.info > div:last-of-type {
  margin-bottom: 0;
}
.info > div img {
  height: 0.18rem;
}
.info > div span {
  font-size: 0.13rem;
  color: #000000;
  padding-left: 0.1rem;
}
.info .address {
  justify-content: space-between;
}
.info .address .left {
  width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info .address .right {
  color: #8f8f8f;
}
.mainUnit {
  width: 90%;
  margin: 0.1rem auto 0.14rem;
  background: url("../assets/images/beijing.png") no-repeat left bottom;
  background-color: #fff;
  border-radius: 5px;
  background-size: 100% auto;
  padding: 0.16rem 0.16rem 0.1rem;
}
.mainUnit .mainInfo {
  display: flex;
}
.mainUnit .mainInfo .pic img {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 5px;
}
.mainUnit .mainInfo .text {
  padding-left: 0.14rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: auto;
}
.mainUnit .mainInfo .text .name {
  font-size: 16px;
  font-family: PingFangSC-Medium;
  font-weight: 500;
  color: rgba(0, 0, 0, 1);
}
.mainUnit .mainInfo .text .num {
  display: flex;
  align-items: center;
  font-size: 0.14rem;
  color: #383838;
}
.mainUnit .mainInfo .text .num .num1 {
  padding-right: 0.1rem;
  border-right: 1px solid #8f8f8f;
}
.mainUnit .mainInfo .text .num .num2 {
  padding-left: 0.1rem;
}
.mainUnit .introduction {
  margin-top: 0.2rem;
  font-size: 0.13rem;
  color: #383838;
}
.mainUnit .action {
  margin-top: 0.26rem;
  display: flex;
  justify-content: space-between;
}
.mainUnit .action img {
  width: 1.27rem;
}
.activityDetail {
  background: #fff;
  padding: 0.16rem 0 0.14rem;
}
.activityDetail > div {
  margin-bottom: 0.3rem;
  text-align: center;
}
.activityDetail > div img {
  width: 60%;
}
.footer {
  position: fixed;
  left: 0;
  bottom: 0;
  background: #fff;
  height: 0.5rem;
  width: 100%;
  border-top: 1px solid #cccccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.footer .right {
  background: #00c6d8;
  height: 100%;
  width: 1.54rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.15rem;
  color: #ffffff;
}
.footer .left {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: calc(100% - 1.54rem);
}
.footer .left > div {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
}
.footer .left > div img {
  height: 0.2rem;
}
.footer .left > div span {
  font-size: 0.14rem;
  color: #414141;
}
.dialogContent {
  padding: 0.24rem 0.16rem;
}
.dialogContent .row1 {
  margin-bottom: 0.22rem;
}
.dialogContent label {
  font-size: 0.14rem;
  color: #353535;
  padding-right: 0.14rem;
}
.dialogContent .row1 input {
  width: 2rem;
  height: 0.3rem;
  border-radius: 5px;
  border: 1px solid #e5e5e5;
  padding-left: 0.05rem;
}
.dialogContent .row2 font {
  border: 1px solid #e5e5e5;
  width: 2rem;
  height: 0.3rem;
  display: inline-block;
  border-radius: 5px;
  border-right: none;
}
.dialogContent .row2 input {
  width: 1.16rem;
  height: 0.3rem;
  padding-left: 0.05rem;
  border: none;
}
.dialogContent .row2 span {
  width: 0.77rem;
  height: 0.3rem;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
  background: #00c6d8;
  color: #fff;
  font-size: 0.12rem;
  display: inline-block;
  vertical-align: top;
  text-align: center;
  line-height: 0.3rem;
}
.bindPhone >>> .van-dialog__confirm,
.bindPhone >>> .van-dialog__confirm:active {
  color: #00c6d8;
}
.van-actionsheet__header {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  padding: 0.3rem 0.4rem 0;
  font-size: 0.18rem;
  color: #000000;
}
.chooseSku .content {
  margin-top: 0.24rem;
}
.chooseSku .content .ticket {
  padding: 0 0.12rem;
  width: 100%;
}
.chooseSku .content .ticket .row1 {
  margin-bottom: 0.08rem;
}
.chooseSku .content .ticket .row1 .ticketBox {
  width: 100%;
  height: 0.38rem;
  border: 1px solid rgba(211, 211, 211, 1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.1rem;
}
.chooseSku .content .ticket .row .ticketBox .name {
  font-size: 0.13rem;
  color: #000;
}
.chooseSku .content .ticket .row .ticketBox .price {
  font-size: 0.15rem;
  color: #00c6d8;
}
.chooseSku .content .ticket .row2 {
  display: flex;
  justify-content: space-between;
}
.chooseSku .content .ticket .row2 .ticketBox {
  width: 49%;
  height: 0.38rem;
  border: 1px solid rgba(211, 211, 211, 1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.1rem;
}
.chooseSku .content .num {
  margin-top: 0.23rem;
  padding: 0 0.23rem;
  display: flex;
  align-items: center;
}
.chooseSku .content .num label {
  padding-right: 0.16rem;
  font-size: 0.15rem;
  color: #000;
}
.chooseSku .content .next {
  margin-top: 0.2rem;
  padding-left: 0.12rem;
  display: flex;
  width: 100%;
  height: 0.5rem;
}
.chooseSku .content .next .total {
  width: 60%;
  display: flex;
  align-items: center;
  font-size: 0.15rem;
  color: #000;
  border-top: 1px solid #d3d3d3;
}
.chooseSku .content .next .btn {
  width: 40%;
  display: flex;
  align-items: center;
  font-size: 0.17rem;
  color: #fff;
  background: #00c6d8;
  justify-content: center;
}
.activityContent >>> img {
  width: 100%;
}
.bindPhone .van-overlay {
  z-index: 1000 !important;
}
.downloadDialog {
  padding: 0.3rem;
}
.downloadDialog .text {
  text-align: center;
  margin-bottom: 0.2rem;
}
.downloadDialog .btn {
  width: 100%;
  height: 0.4rem;
  background: #00c6d8;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}
.selectTicket {
  background: #00c6d8;
  color: #fff !important;
  border: 1px solid #00c6d8 !important;
}
.selectTicket .name {
  color: #fff !important;
}
.selectTicket .price {
  color: #fff !important;
}
.chooseSku >>> .van-overlay {
  z-index: 1000 !important;
}
.signUp >>> .van-overlay {
  z-index: 1000 !important;
}
.signUp .form {
  padding: 0.1rem 0.2rem;
}
.signUp .form .name {
  margin-bottom: 0.2rem;
}
.signUp .form input {
  width: 2.75rem;
  height: 0.4rem;
  border: 1px solid #cacaca;
  padding-left: 0.1rem;
}
.signUp .form label {
  font-size: 0.15rem;
  font-family: PingFangSC-Regular;
  font-weight: 400;
  color: rgba(0, 0, 0, 1);
}
.price2 {
  color: #6b6b6b !important;
}
.btn2 {
  background: #bfbfbf !important;
}
</style>


